package com.ruoyi.framework.mybatis;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * @author : hcl
 * @Date : 2023/8/23 16:05
 * 查询数据获取ids
 */
public class SelectDataGetIds extends AbstractMethod {
    public SelectDataGetIds() {
        this("findIds");
    }

    public SelectDataGetIds(String methodName) {
        super(methodName);
    }

    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        String methodSql = "<script>%s SELECT id FROM %s %s %s %s\n</script>";
        String sql = String.format(methodSql, this.sqlFirst(), tableInfo.getTableName(), this.sqlWhereEntityWrapper(true, tableInfo), this.sqlOrderBy(tableInfo), this.sqlComment());
        SqlSource sqlSource = this.languageDriver.createSqlSource(this.configuration, sql, modelClass);
        return this.addSelectMappedStatementForOther(mapperClass, this.methodName, sqlSource, Long.class);
    }
}
